<?php 
$link = mysql_connect('localhost', 'root', '');
//$link = mysql_connect('aecabill.accountsupportmysql.com', 'aeca', 'fArC5YyyG8NT9wdC5LXP');
if (!$link) { 
     die('There appeared to be an error while connecting to the website database: ' . mysql_error()); 
}
mysql_select_db(aeca);

$user_id = $_POST['uid'];
$query = "select * from tbl_reporting_personnel where rp_id=$user_id";
$result = mysql_fetch_array(mysql_query($query));

$cquery = "select * from  tbl_companies";
$cresult = mysql_query($cquery);

?>
<script>
$(function() {
	$( "#accordion" ).accordion();
	
	$(".userEdit").click(function() { 
     // validate and process form here
     $("#personal_info").validate();
     var name = 'EditUser';
     var uid = $("#uid").val();
     var rp_first_name = $("#rp_first_name").val();
     var rp_last_name = $("#rp_last_name").val();
     var c_nickname = $("#c_nickname").val();
     var rp_phone_number = $("#rp_phone_number").val();
     var rp_phone_ext = $("#rp_phone_ext").val();
     var rp_fax_number = $("#rp_fax_number").val();
     var rp_email = $("#rp_email").val();
     var rp_user_name = $("#rp_user_name").val();
     var user_level = $("#user_level").val();
     if(rp_email != '' && rp_user_name != ''){
		 $.post("/aec1/pages/update_cprofile.php",{name:name,uid:uid,rp_first_name:rp_first_name,rp_last_name:rp_last_name,c_nickname:c_nickname,rp_phone_number:rp_phone_number,rp_phone_ext:rp_phone_ext,rp_fax_number:rp_fax_number,rp_email:rp_email,rp_user_name:rp_user_name,user_level:user_level},function(data){
		   	$( "#dialog:ui-dialog" ).dialog( "destroy" );
			$( "#dialog-message_u" ).dialog({
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog( "close" );
						window.location = "index.php?page=reporting-personnel";
					}
				}
				});
				
		 });
		 return false;
     }
   });  
   
   $(".resetPWD").click(function() { 
     // validate and process form here
     var name = 'reset password';
     var uid = $("#userid").val();
	 $.post("/aec1/pages/update_cprofile.php",{name:name,uid:uid},function(data){
	 if(data == 1){
	   	$("#success").text("An email containing your new password has been sent.").show();
	 }else if(data == 0){
	 	$("#error").text("There was an error while attempting to reset your password. Please contact AECA.").show();
	 }
	});
	return false;
   });  
});

</script>
<!-- ui-dialog -->
<div id="dialog-message_u" title="Success Update" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
		The Reporting Personnel has been Updated Successfully.
	</p>
</div>

<span id='error'></span><span id='success'></span>
<div id="accordion">
	<h3><a href="#">Edit Reporting Personnel</a></h3>
<div>
<!-- <form action="index.php?page=edit-reporting-personnel&Id=<?=$user_id?>" method="post" id="personal_info"> -->
<form action="" method="post" id="personal_info">
<table cellpadding="4">
	<tr>
		<td><label><strong>First Name :</strong></label></td>
		<td><input type="text" name="rp_first_name" value="<?=$result[2];?>" id="rp_first_name" /></td>
	</tr>
	<tr>
		<td><label><strong>Last Name :</strong></label></td>
		<td><input type="text" name="rp_last_name" value="<?=$result[3];?>" id="rp_last_name" /></td>
	</tr>
	<tr>
		<td><label><strong>Company Name :</strong></label></td>
		<td>
		<select name="c_nickname" id="c_nickname">
		<? while($crow = mysql_fetch_array($cresult)){?>
										<option value=<?=$crow['c_nickname'];?>
										<? if($result[1] == $crow['c_nickname']){ echo 'selected="selected"'; } else {} ?>
										><?=$crow['c_nickname'];?></option>
		<?}?>
		</select>
		</td>
	</tr>
	<tr>
		<td><label><strong>Phone Number :</strong></label></td>
		<td><input type="text" name="rp_phone_number" value="<?=$result[4];?>" id="rp_phone_number" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Extension :</strong></label></td>
		<td><input type="text" name="rp_phone_ext" value="<? echo $result[5];?>" id="rp_phone_ext" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Fax Number :</strong></label></td>
		<td><input type="text" name="rp_fax_number" value="<? echo $result[6];?>" id="rp_fax_number" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Email* :</strong></label></td>
		<td><input type="text" name="rp_email" value="<? echo $result[7];?>" id="rp_email" class="required email"/></td>
	</tr>
	<tr>
		<td><label><strong>Username* :</strong></label></td>
		<td><input type="text" name="rp_user_name" value="<? echo $result[8];?>" id="rp_user_name" class="required"/></td>
	</tr>
	<tr>
		<td><label><strong>User Level :</strong></label></td>
		<td>
		<select name="user_level" id="user_level">
			<option value="1" <? if($result[10] == '1'){ echo 'selected="selected"'; } else {} ?>>Read Only</option>
			<option value="2" <? if($result[10] == '2'){ echo 'selected="selected"'; } else {} ?>>Company Reporter</option>
			<option value="4" <? if($result[10] == '4'){ echo 'selected="selected"'; } else {} ?>>AECA Admin</option>
		</select>
		</td>
	</tr>
	<tr>
		<td>&nbsp;<input type="hidden" name="userid" value="<?=$user_id?>" id="uid"/></td>
		<td><input type="submit" value="Submit" name="submit" class="userEdit" />
		<input type="button" value="Cancel" name="cancel" onclick="location.href='index.php?page=reporting-personnel'"/>
		</td>
	</tr>
</table>
</form>
</div>
	<h3><a href="#">Reset Password</a></h3>
	<div>
	<!-- <form method="POST" action="index.php?page=edit-reporting-personnel&Id=<?=$user_id?>"> -->
	<form method="POST" action="">
		<table>
			<tr>
				<td>Username:</td>
				<td><?=$result[8];?><input type="hidden" name="userid" value="<?=$user_id?>" id="userid"/></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type="submit"  name="reset" value="Reset Password" class="resetPWD" /></td>
			</tr>
		</table>
	</form>
	</div>
</div>